#include "Camera.h"
#include "Scene.h"

void Camera::OnKeyBoardDownEvent(const SDL_KeyboardEvent& Event)
{
}

Camera::Camera() : 
m_pos(0,0,0), 
m_look(1,0,0), 
m_up(0,1,0), 
m_w(-1,0,0), 
m_u(0,-1,0), 
m_v(1,0,0),
m_near(1.0f), 
m_far(10.0f)
{}

const Vec3& Camera::GetPos()
{
    return m_pos;
}

void Camera::ComputeDirection(int x, int y, Vec3* target, Scene* s)
{
    float pX = s->m_pixelSize * (x - (0.5f * (s->m_resX - 1))) / s->m_resX / 2;
    float pY = s->m_pixelSize * (y - (0.5f * (s->m_resY - 1))) / s->m_resY / 2;
    *target = (m_u * pX) + (m_v * pY) - (m_w * m_near);
    target->normalise();
}

void Camera::SetPosition( const Vec3& pos )
{
    m_pos = pos;
}

void Camera::SetPosition( float x, float y, float z )
{
    m_pos.SetStats(x,y,z);
}

void Camera::SetLook( const Vec3& look )
{
    m_look = look;
}

void Camera::SetLook( float x, float y, float z )
{
    m_look.SetStats(x,y,z);
}

void Camera::SetUp( const Vec3& up )
{
    m_up = up;
}

void Camera::SetUp( float x, float y, float z )
{
    m_up.SetStats(x,y,z);
}

void Camera::ComputeONB()
{
    m_up.normalise();
    //opposite of the look vector
    m_w = m_pos - m_look;
    m_w.normalise();

    //perpendicular to m_w
    m_u = m_up.CrossProduct(m_w);
    m_u.normalise();

    //perpendicular to u and w
    m_v = m_w.CrossProduct(m_u);
}